import Vue from 'vue'
import Vuex from 'vuex'

import {
  sysKnowledgeQueryById,
  openApiSysKnowledgeQuery,
  sysKnowledgeQueryKnowledgeRelation,
} from '@/api/admin/courseLibrary/sysKnowledge'
Vue.use(Vuex)

const state = {
  knowledge: {},
}

const getters = {}

const actions = {
  async queryOpenApiSysKnowledgeList({ commit }, listQuery) {
    let res = await openApiSysKnowledgeQuery({ ...listQuery })
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async querySysKnowledgeById({ commit }, listQuery) {
    let res = await sysKnowledgeQueryById({ ...listQuery })
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  //查询章节下所有知识点及标记
  async querySysKnowledgeRelation({ commit }, listQuery) {
    let res = await sysKnowledgeQueryKnowledgeRelation({ ...listQuery })
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  //   async testPaperDel({ commit }, row) {
  //     let res = await testPaperDelete(row.id)
  //     return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  //   },
  //   async testPaperADD({ commit }, data) {
  //     let res = await testPaperAdd(data)
  //     return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  //   },
  //   async testPaperUPDATE({ commit }, data) {
  //     let res = await testPaperUpdate(data)
  //     return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  //   },
}

const mutations = {
  SET_KNOWLEDGE: (state, d) => {
    state.knowledge = d
  },
}

export default {
  state,
  getters,
  actions,
  mutations,
}
